// @file      ImageMagick.groovy
// @author    Mac Radigan
// @purpose   a wrapper for convert

package ycoa.graphics

import ycoa.configuration.*

def class ImageMagick {

  private String convertPath = null

  public ImageMagick() {
    def configuration = YCOAConfiguration.getConfiguration()
    this.convertPath = configuration.tools.convert
  }

  public void rotate(infile, outfile, angle) {
    def initialSize = 4096
    def outStream = new ByteArrayOutputStream(initialSize)
    def errStream = new ByteArrayOutputStream(initialSize)
    def cmdConvert = "${convertPath} ${infile} -rotate ${angle} ${outfile} "
    println '  [execute]   '+cmdConvert
    def procConvert = cmdConvert.execute()
    procConvert.consumeProcessOutput(outStream, errStream)
    procConvert.waitFor()
    if(procConvert.exitValue()) {
      println errStream
    } else {
      println outStream
    }
    //new File('out.log') << outStream
    //new File('out.err') << errStream
  } 

}

// *EOF*

